// 公共的方法

/* common/js/utils.js */
const PubFuc = {
	// 格式化时间戳
	formatTime: (value) => {
		var value = String(value);

		function t(v) {
			return v = v < 10 ? ("0" + v) : v;
		}
		String.prototype.ToString = function(value) {
			var date = new Date(parseInt(this.substring(6, this.length - 2)));
			value = value.replace("yyyy", date.getFullYear());
			value = value.replace("yy", t(date.getFullYear().toString().substr(2)));
			value = value.replace("MM", t(date.getMonth() + 1));
			value = value.replace("dd", t(date.getDate()));
			value = value.replace("hh", t(date.getHours()));
			value = value.replace("mm", t(date.getMinutes()));
			value = value.replace("ss", t(date.getSeconds()));
			value = value.replace("ms", date.getMilliseconds())
			return value;
		};
		return value.ToString("yyyy-MM-dd  hh:mm:ss");
	},
	convertISOToCustomFormat: (isoString) => {
		// 函数用于将 ISO 8601 格式的时间字符串转换为自定义格式的时间字符串,将2024-05-22T11:40:19.109Z变为2024-05-22 19:40:19
		const date = new Date(isoString);

		const year = date.getFullYear();
		const month = (date.getMonth() + 1).toString().padStart(2, '0');
		const day = date.getDate().toString().padStart(2, '0');
		const hours = date.getHours().toString().padStart(2, '0');
		const minutes = date.getMinutes().toString().padStart(2, '0');
		const seconds = date.getSeconds().toString().padStart(2, '0');

		const customFormat = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;

		return customFormat;
	}
}

export default PubFuc